<div class="content">
	<div class="tab_bar">
		<ul>
			<li class="tab_index" onclick="setTabContent(this);"><h3>添加分类</h3></li>
		</ul>
		<button class="btn_tabbar" onclick="submitForm(this);" return="category/list.do">保 存</button>
	</div>
	<form id="myForm" action="category/save.do" method="post">
	<input id="rootFeild" name="root" value="1" type="hidden" />
	<div class="tab_content">
		<div class="tab_item tab_show">
			<table class="table_for_add">
				<tbody>
				   <tr>
						<th width="140">上级菜单：</th>
						<td>
							<select id="categorySelect" class="select_for_add" name="pid" onchange="changePid(this)">
								<option value="0"> -------- 根级分类 -------- </option>
								<@categoryTree id = 0 node = -1/>
							</select>
						</td>
						<td></td>
					</tr> 
					<tr id="modelSelect" class="rowBgColor">
						<th width="140">内容模型：</th>
						<td>
						<select id="modelFeild" class="select_for_add"  name="model">
							<option value="">无内容模型</option>
							<#list models as model>
							<option value="${model.type!}">${model.name!}</option>
							</#list>
						</select>
						</td>
						<td><span id="name_status"></span></td>
					</tr> 
						
					<tr class="rowBgColor">
						<th width="140">分类名称：</th>
						<td><input class="input_for_add" name="name" type="text" /></td>
						<td><span id="name_status"></span></td>
					</tr>
				    <tr>
						<th width="140">分类别名：</th>
						<td><input class="input_for_add" name="alias" type="text" /></td>
						<td><span id="name_status"></span></td>
					</tr>
					<tr class="rowBgColor">
						<th width="140">分类排序：</th>
						<td><input class="input_for_add" name="sort" type="text" value="0" /></td>
						<td><span id="name_status"></span></td>
					</tr>
					<tr >
						<th>描述信息：</th>
						<td>
							<textarea class="textarea_for_add" name="description"></textarea>
						</td>
						<td>
							<span id="address_status"></span>
						</td>
					</tr>
				</tbody>
			</table>
		</div>
	</div>
	</form> 
</div>
<script type="text/javascript">
function changePid(obj){
	var pid = $(obj).val();
	var model = $("#categorySelect option:selected").attr("model");
	
	if(pid == 0 ){
		$("#modelSelect").show();
		$("#rootFeild").val(1);
	}else{// 非根节点
		$("#modelSelect").hide();
		$("#modelFeild").val(model);
		$("#rootFeild").val(0); 
	} 
}

function submitForm(obj){
	if($("#categorySelect").val() == 0){
		if($("#modelFeild").val() == ""){
			zoom.showMessageDialog("请选择内容模型！","消息提示",1500);
			return;
		}
	}
	
	
	submitActionForm(obj);
}

</script>



<#-- 树形结构生成器 -->
<#macro categoryTree id node>
	<#local temp = node + 1 />
	<#list data as x>
		<#if x.id != 0>
		  	<#if id = x.pid>
		  		<option value="${x.id?c}" model="${x.model!}"><#if temp gt 0 ><#list 1..temp as i>&nbsp; &nbsp;</#list>┆┄</#if> ${x.name!} </option>
		    <@categoryTree id = x.id node=temp/>
	      	</#if>
      	</#if>
	</#list> 
</#macro>

